package com.twu.biblioteca;

import java.util.ArrayList;

/**
 * Created with IntelliJ IDEA.
 * User: twer
 * Date: 10/12/13
 * Time: 11:29 AM
 * To change this template use File | Settings | File Templates.
 */
public class Menu {
    private static final String MY_ACCOUNT = "My Account";
    private static final String BOOK = "Books";
    private static final String MOVIES = "Movies";
    private static final String INPUT_PROMPT = "Enter the Menu NO. : ";
    private static final String ERROR_PROMPT = "Select a valid option!";

    private ArrayList<String> _menuItem = new ArrayList<String>();

    public Menu(){
        _menuItem.add(MY_ACCOUNT);
        _menuItem.add(BOOK);
        _menuItem.add(MOVIES);
    }

    public ArrayList<String> getItems(){
        return _menuItem;
    }

    public String getInputPrompt(){
        return INPUT_PROMPT;
    }

    public String getErrorPrompt(){
        return  ERROR_PROMPT;
    }

    public boolean selectedOptionValidation(String selectedOption) {
        if(selectedOption == null){
            return false;
        }
        else{
            int optionNum = Integer.parseInt(selectedOption);
            return optionNum>=1 && optionNum<= getItems().size();
        }
    }

    public String inputOption(User user) {
        boolean isValid = false;
        String selectedOption = null;
        while(!isValid){
            selectedOption = user.getUserInput(getInputPrompt());
            isValid = selectedOptionValidation(selectedOption);
            if(isValid) break;
            System.out.println(getErrorPrompt());
        }
        return selectedOption;
    }

}
